package com.CuiChangHe.studentmanager.service.studentexaminfo.impl;

import com.CuiChangHe.studentmanager.dao.StudentExamInfoDao;
import com.CuiChangHe.studentmanager.entity.studentexaminfo.StudentExamInfoData;
import com.CuiChangHe.studentmanager.entity.studentexaminfo.StudentExamInfoReturnMsg;
import com.CuiChangHe.studentmanager.mapper.StudentExamInfoMapper;
import com.CuiChangHe.studentmanager.service.studentexaminfo.StudentExamInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * @Description :学生考试信息业务实现
 * @Author :崔昌赫
 * @Date : 2021/11/19
 */
@Service
@Slf4j
public class StudentExamInfoServiceImpl implements StudentExamInfoService {

    private StudentExamInfoMapper mapper;

    @Autowired
    public void setMapper(StudentExamInfoMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    @Transactional(readOnly = true)
    public StudentExamInfoReturnMsg getAllStudentExamInfo() {
        StudentExamInfoReturnMsg returnMsg = new StudentExamInfoReturnMsg();
        log.info("开始查找所有学生成绩信息.");
        StudentExamInfoDao[] allStudentExamInfo = mapper.getAllStudentExamInfo();
        if (allStudentExamInfo==null){
            log.warn("查找所有学生信息失败!返回为空!");
            returnMsg.setCode(50000);
            returnMsg.setMessage("查找所有学生信息失败!");
            return returnMsg;
        }
        log.info("查找结果:{}", Arrays.toString(allStudentExamInfo));
        returnMsg.setCode(20000);
        returnMsg.setMessage("查找成功.");
        returnMsg.setData(new StudentExamInfoData(allStudentExamInfo.length,allStudentExamInfo));
        log.info("本次业务结束.");
        return returnMsg;
    }
}
